<html>
	<head>
		<script src="../gears_init.js"></script>
		<script src="../GearsORM.js"></script>
		<script src="../GearsORM.Events.js"></script>
		<script src="../GearsORM.ResultIterator.js"></script>
		<script src="../GearsORM.Sql.js"></script>
		<script src="../GearsORM.Fields.js"></script>
		<script src="../GearsORM.Model.js"></script>
		<script src="../GearsORM.Introspection.js"></script>
		<script src="../GearsORM.Transaction.js"></script>
		<script>
			GearsORM.dbName = "test.simple1";
			var Person = new GearsORM.Model({
				name:"Person",
				fields:
				{
					firstName:new GearsORM.Fields.String({maxLength:25}),
					lastName:new GearsORM.Fields.String({maxLength:25})
				}
			});
			
			var Tests =
			{
				up:function()
				{
					Person.dropTable();
					Person.createTable();
				},
				"test if create works":function()
				{
					var someone = new Person();
					someone.firstName = "Jhon";
					someone.lastName = "Doe";
					someone.save();
					UnitTest.assertDefined(someone.rowid,"someone wasn`t inserted");
				},
				"test if retrive using constructor work":function()
				{
					var someone = new Person(1);
					UnitTest.assertTrue(someone.firstName == "Jhon","first name is wrong");
					UnitTest.assertTrue(someone.lastName == "Doe","last name is wrong");
				},
				"test if update works":function()
				{
					var someone = new Person(1);
					someone.firstName = "updated";
					someone.save();
					var fromDb = new Person(1);
					UnitTest.assertTrue(fromDb.firstName == "updated","someone wasn`t updated");
				},
				"test if count works":function()
				{
					UnitTest.assertEqual(1,Person.count());
					new Person({firstName:"test",lastName:"test"}).save();
					UnitTest.assertEqual(2,Person.count());
					UnitTest.assertEqual(1,Person.count("firstName = ?",["test"]));
				},
				"test if delete works":function()
				{
					var someone = Person.select().getOne();
					var id = someone.rowid;
					someone.remove();
					UnitTest.assertTrue(
						Person.select("rowid = ?",[id]).getOne() == false,
						"someone wasn`t delete"
					); 
				},
				down:function()
				{
					Person.dropTable();
				}
			};
		</script>
		<script src="unit_test.js"></script>
	</head>
	<body>
		
	</body>
</html>